package cn.itcast.zt.java8.excel;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileMode;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.itcast.zt.java8.stream.Person;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangtian105
 * @ClassName ExcelDemo.java
 * @projectName Java8
 * @Description
 * @createTime 2020年07月21日 18:46:00
 */
public class ExcelDemo {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>() ;
        for (int i = 0; i < 10; i++) {
            Person person = Person.builder()
                    .name("人类昵称"+i)
                    .realName("人类真名"+i)
                    .age(1+i).build() ;
            personList.add(person) ;
        }

        File files = new File("d:\\我的文档\\桌面\\" + "达人考核看板数据.xlsx") ;
        if (!files.exists()) {
            FileUtil.createRandomAccessFile(files, FileMode.rw) ;
        }

        ExcelWriter writer = ExcelUtil.getWriter(files, "达人考核看板数据") ;
        writer.merge(personList.size(), "达人考核看板数据") ;
        writer.write(personList, true) ;

        writer.flush() ;
        writer.close();
    }
}
